﻿Imports EVOLTA.Promocion.Bl.Bc
Imports EVOLTA.Promocion.Bl.Be

Partial Class seguridad_menu
    Inherits System.Web.UI.Page
    Private Eestados As List(Of Ecommon) = Nothing
    Dim Evolta As Eevolta = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Response.AddHeader("Pragma", "no-cache")
        Response.Expires = -1
        '***********************************************************'
        If Not IsPostBack Then
            'Try
            Me.sRuta = Nothing
            If Request("txtUsuario") Is Nothing OrElse Request("txtEmpresa") Is Nothing Then
                If Me.Master.sEvolta Is Nothing Then
                    Response.Redirect(ConfigurationManager.AppSettings("cerrar").ToString)
                End If
            Else
                Dim empresa As Boolean = False
                For x As Int32 = 0 To ConfigurationManager.ConnectionStrings.Count - 1
                    If Request("txtEmpresa").ToUpper.Equals(ConfigurationManager.ConnectionStrings(x).Name) Then
                        empresa = True
                        Exit For
                    End If
                Next
                If empresa = True AndAlso _
                   Request("txtEmpresa").Length > 0 AndAlso _
                   Request("txtUsuario").Length > 0 Then
                    Dim mensaje As String = Nothing
                    Dim idUsuario As Int32 = 0
                    Dim idPerfilUsuario As Int32 = 0
                    Dim intentos As Int32 = Rusuario.comprobarUsuario(Request("txtEmpresa").Trim.ToUpper, _
                                                                      Request("txtUsuario").Trim.ToUpper, _
                                                                      Request("txtPassword").Trim.ToUpper, _
                                                                      idUsuario, _
                                                                      "", idPerfilUsuario)
                    If intentos > 0 Then
                        Evolta = New Eevolta
                        With Evolta
                            .mostrarMenu = True
                            Me.menu = True

                            .descEmpresa = Request("txtEmpresa").ToString
                            Me.Master.descEmpresa = .descEmpresa
                            Me.empresa = .descEmpresa

                            .idUsuario = idUsuario
                            Me.Master.idUsuario = .idUsuario
                            Me.idUsuario = .idUsuario

                            .descUsuario = Request("txtUsuario").ToString
                            Me.Master.descUsuario = .descUsuario
                            Me.usuario = .descUsuario

                            .idPerfilUsuario = idPerfilUsuario
                            Me.Master.idPerfilUsuario = idPerfilUsuario
                            Me.idPerfilUsuario = idPerfilUsuario
                        End With
                        Me.Master.sEvolta = Evolta
                        Dim Eestado As New Ecommons
                        gvwPlataformas.DataSource = Eestado.plataformas
                        gvwPlataformas.DataBind()
                        upPlataformas.Update()

                        Dim strAmbiente As String = String.Empty
                        strAmbiente = ConfigurationManager.AppSettings("Ambiente").ToString()

                        If strAmbiente.Equals("DESARROLLO") Then
                            Session("ssn_Url") = ConfigurationManager.AppSettings("UrlProyectoDesarrollo").ToString()
                        ElseIf strAmbiente.Equals("PRODUCCION") Then
                            Session("ssn_Url") = ConfigurationManager.AppSettings("UrlProyectoProduccion").ToString()
                        End If
                    Else
                        If Me.Master.sEvolta Is Nothing Then
                            Response.Redirect(ConfigurationManager.AppSettings("cerrar").ToString)
                        End If
                    End If
                End If
                End If
        End If
        Me.Master.mostrarMenu = False
    End Sub
    Protected Sub gvwPlataformas_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvwPlataformas.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("OnMouseOver", "Resaltar_On(this);")
            e.Row.Attributes.Add("OnMouseOut", "Resaltar_Off(this);")
            e.Row.Attributes("OnClick") = Page.ClientScript.GetPostBackClientHyperlink(Me.gvwPlataformas, "Select$" + e.Row.RowIndex.ToString)
            e.Row.Style.Add("cursor", "hand")
        End If
    End Sub
    Protected Function rutaPlataforma(ByVal descripcion As String) As String
        Dim ruta As String = Nothing
        Select Case descripcion
            Case "1"
                ruta = "~/seguridad/bienvenida.aspx?menu=" & menu & "&idUsuario=" & idUsuario & "&usuario=" & usuario & "&empresa=" & empresa & "&idPerfilUsuario=" & idPerfilUsuario
            Case "2"
                ruta = "~/proyecto/proyecto.aspx?menu=" & menu & "&idUsuario=" & idUsuario & "&usuario=" & usuario & "&empresa=" & empresa & "&idPerfilUsuario=" & idPerfilUsuario
                Session("sRuta") = ruta
        End Select
        Return ruta
    End Function
    Private Property sRuta() As String
        Get
            If Session("sRuta") Is Nothing Then
                Return Nothing
            Else
                Return Session("sRuta")
            End If
        End Get
        Set(ByVal value As String)
            Session("sRuta") = value
        End Set
    End Property
    Public Property menu() As Boolean
        Get
            Return hdMenu.Value
        End Get
        Set(ByVal value As Boolean)
            hdMenu.Value = value
        End Set
    End Property
    Public Property empresa() As String
        Get
            Return hdEmpresa.Value
        End Get
        Set(ByVal value As String)
            hdEmpresa.Value = value
        End Set
    End Property
    Public Property idUsuario() As Int32
        Get
            Return hdIdUsuario.Value
        End Get
        Set(ByVal value As Int32)
            hdIdUsuario.Value = value
        End Set
    End Property
    Public Property usuario() As String
        Get
            Return hdUsuario.Value
        End Get
        Set(ByVal value As String)
            hdUsuario.Value = value
        End Set
    End Property
    Public Property idPerfilUsuario() As Int32
        Get
            Return hdIdPerfil.Value
        End Get
        Set(ByVal value As Int32)
            hdIdPerfil.Value = value
        End Set
    End Property

End Class
